﻿using System;
using System.Collections.Generic;
using System.Configuration;

namespace FTPC.Config {
    sealed class ConfigMgr {
        private static ConfigMgr _instance;

        public Configuration _cfg;

        private ApplicationConfig _application;

        public static ConfigMgr Instance {
            get {
                if (_instance == null) {
                    _instance = new ConfigMgr ( );
                }
                return _instance;
            }
        }

        public ApplicationConfig Application {
            get {
                return this._application;
            }
        }

        /// <summary>
        /// 读取配置文件
        /// </summary>
        private ConfigMgr() {
            ExeConfigurationFileMap file = new ExeConfigurationFileMap ( );
            file.ExeConfigFilename = System.Environment.CurrentDirectory + "\\" + "ChartViewer.xml";
            _cfg = ConfigurationManager.OpenMappedExeConfiguration (file, ConfigurationUserLevel.None);
            this._application = _cfg.Sections[ApplicationConfig.SECTION_NAME] as ApplicationConfig;
            _cfg.Save (ConfigurationSaveMode.Modified);
        }
    }
}
